package com.tanhua.dubbo.api.impl;

import com.tanhua.domain.mongo.SoulQuestion;
import com.tanhua.dubbo.api.SoulQuestionApi;
import org.apache.dubbo.config.annotation.Service;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class SoulQuestionApiImpl implements SoulQuestionApi {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public List<SoulQuestion> findQuestionByEid(String Eid) {

        Query query = new Query(Criteria.where("Eid").is(Eid));
        List<SoulQuestion> questionList = mongoTemplate.find(query, SoulQuestion.class);
        return questionList;
    }

    @Override
    public List<SoulQuestion> findQuestionAll() {
        Query query = new Query();
        List<SoulQuestion> questionList = mongoTemplate.find(query, SoulQuestion.class);
        return questionList;
    }

    @Override
    public SoulQuestion findQuestionById(ObjectId id) {
        SoulQuestion soulQuestion = mongoTemplate.findById(id, SoulQuestion.class);
        return soulQuestion;
    }
}
